package exercises.Charpter10;

interface U{
	void f1(String x);
	void f2(String x);
	void f3(String x);
}

class A{
	U getU(){
		return new U(){

			@Override
			public void f1(String x) {
				System.out.println(x + "A.ananymous f1");
			}

			@Override
			public void f2(String x) {
				System.out.println(x + "A.ananymous f2");
			}

			@Override
			public void f3(String x) {
				System.out.println(x + "A.ananymous f3");
			}
			
		};
	}
}

class B{
	U[] array = new U[10];
	int i = 0;
	
	public void addArray(U x){
		array[i++] = x;
	}
	
	public void clearArray(int p){
		if ((p >= 0) && (p < i)){
			array[p] = null; 
		}
	}
	
	public void all(){
		for (int j = 0; j < i; j++){
			if (array[j] != null ){
				array[j].f1(Integer.toString(j));
				array[j].f2(Integer.toString(j));
				array[j].f3(Integer.toString(j));
			}
		}
	}
}

public class Twentythree {
	public static void main(String[] args){
		A generator = new A();
		B ans = new B();
		for (int i = 0; i < 10; i++){
			ans.addArray(generator.getU());
		}
		ans.all();
		ans.clearArray(4);
		ans.all();
	}
}
